local skyent = require("skynet")
local server_name = skyent.getenv("server_name")
local server_id   = tonumber(skyent.getenv("server_id"))
local string_format = string.format

local M = {}

------------------------------------------------------------运维需要关心的配置项--------------------------------------------------
local db_conf = {
	redis = {ip = '127.0.0.1',auth = nil,port = 6379},  --游戏内部使用redis的ip和密码
	mongo = {ip = '127.0.0.1',auth = nil, port = 27017, user = 'admin', dbname = 'yange_data'},  --游戏内部使用mongo的ip和密码
	kafka = {ip = '192.168.50.126',port = 9092, topic = 'bills_log'},  --kafka消息队列
}
M.db_conf = db_conf
-- M.dns_address = '192.168.100.4' --dns地址 已经废弃 运维无需关心
-- M.dns_port = 53 --dns端口 已经废弃 运维无需关心

M.gateway_listen_port = 8550 --网关对外监听端口
M.gateway_max_client  = 1000  --单个网关连接上限

M.webserver_url = '192.168.50.126:9001' --PHP API地址 游戏服跟PHP走的是内网通道 切勿配置成外网通道
M.config_server_url = '192.168.50.234:6661' --web-config 地址 请求游戏配置使用

--内部服务器调试端口  端口全部只有内网开放，无需对外网开放
local server_index = {
	gateway      = 60001,
	proxy        = 60002,
	tablesvr     = 60003,
	hallsvr      = 60004,
	dbsvr        = 60005,
	matchsvr     = 60006,
	accountsvr   = 60007,
	mailsvr      = 60008,
	paysvr       = 60009,
	exdbsvr      = 60010,
	basesvr      = 60011,
	fmatchsvr    = 60012,
	robotmgr     = 60013,
	newmatchsvr  = 60014,
	friendsvr    = 60015,
	confsvr      = 60016,
	websvr       = 60017,
	cardsvr		 = 60021,
	tasksvr	     = 60022,
	table_proxy  = 60023,
	activitysvr  = 60024,
	clubsvr		 = 60025,
	landingsvr	 = 60026,
}

M.debug_port = server_index[server_name]
M.review = 0 --1表示提审(提审的意思是表示IOS马甲包提审标记)
M.is_proxy_gateway = false -- 网关服反代标记 设置为true的话认为该网关的数据是由另外一台反代网关过来 并不是来源客户端的真实数据   (客户端 -->  反代网关 --> 真实网关)
M.log_path = "/data/logs" --日志输出目录



--------------------------------------------------------------下面的配置运维无需关心-----------------------------------------------------------------------
M.debug = true --是不是debug版本 线上统一都是非debug版本
M.defaultLevel = 4
if M.debug then
	M.defaultLevel = 1
end 
M.no_cotainer = true --非容器模式
M.server_id = server_id  --游戏服ID 比如如果有多开网关的话 那么网关1的server_id为1 网关2的server_id为2 以此类推

local REDIS_IP   = db_conf.redis.ip
local REDIS_AUTH = db_conf.redis.auth
local REDIS_PORT = db_conf.redis.port

local MONGO_IP = db_conf.mongo.ip
local MONGO_AUTH = db_conf.mongo.auth
local MONGO_PORT = db_conf.mongo.port
local MONGO_USER = db_conf.mongo.user
local MONGO_DBNAME = db_conf.mongo.dbname

local redis_conf = {
	host = REDIS_IP,
	auth = REDIS_AUTH,
	port = REDIS_PORT,
	db   = 8,
	dirty_queue_db  = 10,
	dirty_queue_key = 'writable_base_queue'
}

local mongo_base_conf = {
	host = MONGO_IP,
	password = MONGO_AUTH,
	port = MONGO_PORT,
	user = MONGO_USER,
	dbname    = MONGO_DBNAME,
	collname  = 'base',
}

local mongo_account_conf = {
	host = MONGO_IP,
	password = MONGO_AUTH,
	port = MONGO_PORT,
	user = MONGO_USER,
	dbname    = MONGO_DBNAME,
	collname  = 'account',
	incrname='account_incr'
}

local mongo_club_conf = {
	host = MONGO_IP,
	password = MONGO_AUTH,
	port = MONGO_PORT,
	user = MONGO_USER,
	dbname    = MONGO_DBNAME,
	collname  = 'club_info',
}

local mongo_db_conf = {
	host = MONGO_IP,
	password = MONGO_AUTH,
	port = MONGO_PORT,
	user = MONGO_USER,
	dbname    = MONGO_DBNAME,
	collname  = 'users',
}

local mongo_mail_conf = {
	host = MONGO_IP,
	password = MONGO_AUTH,
	port = MONGO_PORT,
	user = MONGO_USER,
	dbname    = MONGO_DBNAME,
	collname  = 'users',
}


-- if server_name == 'dbsvr' then
-- 	redis_conf.db = 1
-- 	redis_conf.dirty_queue_db  = 7
-- 	redis_conf.dirty_queue_key = 'writable_uid_queue'
-- elseif server_name == 'tasksvr' or server_name == 'activitysvr' then
-- 	redis_conf.db = 13
-- elseif server_name == 'mailsvr' then
-- 	redis_conf.db = 4
-- 	redis_conf.base_db = 8
-- 	redis_conf.award_db = 15
-- 	redis_conf.dirty_queue_db  = 8
-- 	redis_conf.dirty_queue_key = 'writemail_uid_queue'
-- elseif server_name == 'exdbsvr' then
-- 	redis_conf.db = 7
-- 	redis_conf.ftable_db = 10
-- 	redis_conf.fuser_db = 11
-- 	redis_conf.ontable_db = 12
-- 	redis_conf.notice_db = 13
-- 	redis_conf.fclub_db = 14
-- 	redis_conf.syscoins_db = 15

-- 	redis_conf.store_db = 14
-- elseif server_name == 'robotmgr' then
-- 	redis_conf.db = 9
-- elseif server_name == 'accountsvr' then
-- 	redis_conf.db = 0	--记录uid -- guid
-- elseif server_name == 'friendsvr' then
-- 	redis_conf.income_coins_db = 4
-- 	redis_conf.data_db  = 1
-- 	redis_conf.robot_db = 9
-- 	redis_conf.friend_db = 6
-- elseif server_name == 'cardsvr' then
-- 	redis_conf.db = 7
-- elseif server_name == 'basesvr' then
-- 	redis_conf.db = 8
-- end

M.redis_conf = redis_conf
M.mongo_base_conf = mongo_base_conf
M.mongo_account_conf = mongo_account_conf

M.mongo_club_conf = mongo_club_conf
M.mongo_db_conf = mongo_db_conf
M.mongo_mail_conf = mongo_mail_conf

M.ex_redis_conf = ex_redis_conf

M.proxy_listen_port = 8586
M.proxy_max_client = 200

M.web_listen_ip   = '0.0.0.0'
M.web_listen_port = 8888
M.center_web_slave_count = 2

M.client_ping_interval = 20 --客户端ping时间

M.table_limit = 1000 --每个桌子节点上限1000张桌子
M.phase_swith_time = 600
M.max_match_time = 3

local config_path = "/data/configs"  --配置文件路径 PHP会将后台发布的配置文件上传到该目录 游戏会根据该目录进行加载配置文件
M.config_path = config_path



--basesvr配置
local add_gems = M.debug and 1000 or 0
local add_coins = M.debug and 50000000 or 0
local add_roomcards = M.debug and 600 or 0

--创建初始化的玩家的金币，房卡，钻石
M.init_coins = 0 + add_coins
M.init_roomcards = 0 + add_roomcards
M.init_gems = 0 + add_gems

return M